Setup

Load libraries

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.0
## ✔ readr   2.1.2     ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(cowplot)
library(latex2exp)
library(ggside)
## Registered S3 method overwritten by 'ggside':
##   method from   
##   +.gg   ggplot2
library(ggsci)
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:latex2exp':
## 
##     TeX
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggdist)

Load from cache

co_registered <- readRDS("cache/co_registered.RDS")
cd_pc_data <- readRDS("cache/cd_pc_data.RDS")

Colors

organism_colors <- c("#008c54", "#ffaa00")

Plot

Co-registered

p_co_registered <- co_registered %>% 
  # Plot it!
  ggplot(
    aes(x = at2H_percent,
        y = cd_pc,
        color = as.factor(f_l),
        group = organism.x,
        label = cell_id
    )
  ) +
  geom_point(
    alpha = 0.5,
    size = 2
  ) +
  geom_abline(
    slope = 1,
    linetype = "dashed",
    color = "gray",
    alpha = 1,
  ) +
  stat_smooth(
    formula = y ~ x,
    #formula = y ~ splines::bs(x, 3),
    size = 0.5,
    method = 'lm'
  ) +
  facet_wrap(vars(organism.x)) +
  coord_cartesian(
    xlim = c(0,50), 
    ylim = c(0,50)
  ) +
  scale_color_viridis_d(end = 0.9) +
  theme_bw() +
  labs(
    x = TeX("$^2F$ (atom %)"),
    y = "CD% (Raman)",
    color = TeX("Label Strength $^2F$ (atom %)")
  ) +
  theme(
    legend.position = "bottom",
    ggside.panel.scale = 2
  )
p_co_registered
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).

Plotly

ggplotly(p = p_co_registered)
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## Please use `gather()` instead.
## Warning: Detected the use of `TeX()`, but mathjax has not been specified. Try
## running `config(.Last.value, mathjax = 'cdn')`

CD FL

p_cd_fl <- co_registered %>% 
  filter(!is.na(f_l)) %>% 
  ggplot(
    aes(x = f_l,
        y = cd_pc,
        color = organism.x
        )
  ) +
  labs(
    x = latex2exp::TeX("$^2F$ Growth Water"),
    y = latex2exp::TeX("$^2F_{Raman}$")
  ) +
  facet_wrap(
    vars(organism.x), 
    scales = "free") +
  geom_abline(
    slope = 1,
    linetype = "dashed",
    color = "gray",
    alpha = 1,
  ) +
  geom_point(
    alpha = 0.5,
    position = position_jitter(width = 2)
  ) +
  ggdist::stat_pointinterval(
    position = position_nudge(x = 0.2),
    color = "black"
  ) +
  scale_color_manual(values = organism_colors) + 
  scale_x_continuous(
    limits = c(0, 55),
    breaks = c(0, 10, 20, 30, 40, 50)
    ) +
  scale_y_continuous(
    limits = c(0, 55),
    breaks = c(0, 10, 20, 30, 40, 50)
  ) +
  theme_classic() +
  theme(
    legend.position = "NA",
    strip.background = element_blank()
  )
p_cd_fl
## Warning: Removed 48 rows containing missing values (geom_point).

2F FL

p_2f_fl <- co_registered %>% 
  filter(!is.na(f_l)) %>% 
  ggplot(
    aes(x = f_l,
        y = at2H_percent,
        color = organism.x
        )
  ) +
  facet_wrap(vars(organism.x), scales = "free") +
  geom_abline(
    slope = 1,
    linetype = "dashed",
    color = "gray",
    alpha = 1,
  ) +
  geom_point(
    alpha = 0.5,
    position = position_jitter(width = 2)
  ) +
  scale_color_manual(values = organism_colors) + 
  scale_x_continuous(
    limits = c(0, 55),
    breaks = c(0, 10, 20, 30, 40, 50)
    ) +
  scale_y_continuous(
    limits = c(0, 55),
    breaks = c(0, 10, 20, 30, 40, 50)
  ) +
  labs(
    x = latex2exp::TeX("$^2F$ Growth Water"),
    y = latex2exp::TeX("$^2F_{nanoSIMS}$")
  ) +
  ggdist::stat_pointinterval(
    position = position_nudge(x = 0.2),
    color = "black"
  ) +
  theme_classic() +
  theme(
    legend.position = "NA",
    strip.background = element_blank()
  )
p_2f_fl
## Warning: Removed 35 rows containing missing values (geom_point).

Cowplot: CD-FL and 2F-FL

cowplot::plot_grid(
  p_cd_fl,
  p_2f_fl,
  ncol = 1
)
## Warning: Removed 38 rows containing missing values (geom_point).
## Warning: Removed 36 rows containing missing values (geom_point).

2R FL

co_registered %>% 
  filter(!is.na(f_l)) %>% 
  ggplot(
    aes(x = as.factor(f_l),
        y = `Ratio_2Hx1H`,
        color = organism.x
        )
  ) +
  facet_wrap(vars(organism.x)) +
  geom_point(
    alpha = 0.25
  ) +
  scale_color_manual(values = organism_colors) + 
  labs(
    x = latex2exp::TeX("$^2F$ Growth Water"),
    y = latex2exp::TeX("$^2R_{nanoSIMS}$")
  ) +
  theme_classic() +
  theme(
    legend.position = "NA",
    strip.background = element_blank()
  )

Raman spectrum

cd_pc_data %>% filter(cell_id == "Mb_50_18_38") %>% 
  ggplot(aes(
    x = wavenumber_cm,
    y = intensity
  )) +
  geom_line() +
  theme_minimal()